package com.jstyle.jclife.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jstyle.jclife.R;
import com.jstyle.jclife.utils.DateUtil;

import java.text.NumberFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import lecho.lib.hellocharts.model.BpValue;

/**
 * Created by Administrator on 2018/9/11.
 */

public class BpWeekAdapter extends RecyclerViewBaseAdapter<BpValue> {


    NumberFormat format;


    public BpWeekAdapter(List<BpValue> BpValueList) {
        super(BpValueList);
        format = NumberFormat.getNumberInstance();
        format.setMaximumFractionDigits(1);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        HistoryBpYearViewHolder historyStepWeekViewHolder = (HistoryBpYearViewHolder) holder;
        BpValue bpValueLow = mDataList.get(position*2);
        BpValue bpValueHigh = mDataList.get(position * 2 + 1);
        String showData = bpValueHigh.getShowValue()+ "～" + bpValueLow.getShowValue() ;
        Context context=historyStepWeekViewHolder.itemView.getContext();
        historyStepWeekViewHolder.tvHrvdataDate.setText(DateUtil.getShowDay(context,bpValueLow.getDate()));
        historyStepWeekViewHolder.tvHrvValue.setText(showData);
        historyStepWeekViewHolder.tvHrvLevel.setText(R.string.bp_tips);
    }

    @Override
    public int getItemCount() {
        return mDataList.size() / 2;
    }

    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.item_hrvdata_year;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(getLayoutId(viewType), parent, false);
        BaseViewHolder baseViewHolder = new HistoryBpYearViewHolder(view);
        return baseViewHolder;
    }

    class HistoryBpYearViewHolder extends BaseViewHolder {
        @BindView(R.id.tv_hrvdata_date)
        TextView tvHrvdataDate;
        @BindView(R.id.tv_hrv_value)
        TextView tvHrvValue;
        @BindView(R.id.tv_hrv_level)
        TextView tvHrvLevel;

        public HistoryBpYearViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
